/**
 * @author :JiangYegen
 * 操作js
 */

//退出系统
function logout(){
	ymPrompt.confirmInfo({title:'系统提示',message:'您确定退出系统吗?',handler:function(tp){if(tp=='ok'){window.location.href="index.php?action=exit";}else{}}});
}
//删除图片
function delimg(divId,id){

	ymPrompt.confirmInfo({title:'系统提示',message:'您确定删除吗?',handler:function(tp){if(tp=='ok'){
		var logo=document.getElementById(divId);
		logo.src="./images/mx_wait.gif";
			$.ajax({
				url:'../ajax/deletedata.php',
				type:'post',
				data:{act:"ad_img",id:id},
				success:function(data){
				data=data.replace(/(^\s+)|(\s+$)/g,"");//去除空格     
	           if(data){//true
	        	   var dataObj=eval("("+data+")");
	               	if(dataObj.root[0].status == "true"){
	               		ymPrompt.succeedInfo({title:'系统提示',message:dataObj.root[0].Description});
	               		$("#del_btn").remove();
	               		$("#url1").attr("value",'');
						setTimeout(function(){ymPrompt.doHandler('ok');logo.src="../images/defaultLogo.jpg";},1000);
					   }else{
						ymPrompt.errorInfo({title:'系统提示',message:dataObj.root[0].Description});
						setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},1000);
					   }
					}else{//false
						ymPrompt.errorInfo({title:'系统提示',message:'操作失败'});
						setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},1000);
					}

				},
				error:function(erg){
					ymPrompt.errorInfo({title:'系统提示',message:'出错啦...'});
				}
			});
	}else{return false;}}});
}

//删除管理员ajax
function DelOneadmin(adminid){
	ymPrompt.confirmInfo({title:'系统提示',message:'您确定删除吗?',handler:function(tp){if(tp=='ok'){
		$.ajax({
			url:'../ajax/deletedata.php',
			type:'post',
			data:{act:"admin",adminid:adminid},
			success:function(data){
				data=data.replace(/(^\s+)|(\s+$)/g,"");//去除空格
				//alert(data);return false;
           if (data) {//true
        	   var dataObj=eval("("+data+")");
               	if (dataObj.root[0].status == "true") {

					ymPrompt.succeedInfo({title:'系统提示',message:dataObj.root[0].Description});

					setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);

				   }else if(dataObj.root[0].status == "error"){
					  ymPrompt.alert({title:'系统提示',message:dataObj.root[0].Description});

					  setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);
				   }else{
						ymPrompt.errorInfo({title:'系统提示',message:dataObj.root[0].Description});
						setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);
				   }

				}else {//false
					ymPrompt.errorInfo({title:'系统提示',message:'操作失败'});
					setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);
				}

			},
			error:function(erg){
				ymPrompt.errorInfo({title:'系统提示',message:'出错啦...'});
			}
		});	
	}else{return false;}}});

}

//区域删除ajax
function DelOneArea(area_id){
	ymPrompt.confirmInfo({title:'系统提示',message:'您确定删除吗?',handler:function(tp){if(tp=='ok'){
		$.ajax({
			url:'../ajax/deletedata.php',
			type:'post',
			data:{act:"area",area_id:area_id},
			success:function(data){
				data=data.replace(/(^\s+)|(\s+$)/g,"");//去除空格
           if (data) {//true
        	   var dataObj=eval("("+data+")");
        	   if (dataObj.root[0].status == "true") {

					ymPrompt.succeedInfo({title:'系统提示',message:dataObj.root[0].Description});
					setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);

				   }else if(dataObj.root[0].status == "have"){
					  ymPrompt.alert({title:'系统提示',message:dataObj.root[0].Description});
					  setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);
				   }else{
						ymPrompt.errorInfo({title:'系统提示',message:dataObj.root[0].Description});
						setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);
				   }
				}else {//false
					ymPrompt.errorInfo({title:'系统提示',message:'操作失败'});
					setTimeout(function(){ymPrompt.doHandler('ok');location.reload();},2000);
				}

			},
			error:function(erg){
				ymPrompt.errorInfo({title:'系统提示',message:'出错啦...'});
			}
		});
	}else{return false;}}});
}

//重置登录密码
function resetPwd(adminid){
	var adminid=adminid;
	if(adminid!=""){
		ymPrompt.confirmInfo({title:'系统提示',message:'您确定重置当前管理员密码吗?',handler:function(tp){if(tp=='ok'){window.location.href="admin.php?mod=edit&act=reset&pid="+adminid;}else{}}});
	}else{
		ymPrompt.errorInfo({title:'系统提示',message:'无法重置密码'});
	}

}

//验证管理员是否存在
function chk_admin(fuser,user,adminid){
	var fuser=fuser;
	var user=user;var adminid=adminid;
	var regtext = /^\s*$/;var action=0;
	if(fuser!=""&& regtext.test(fuser)==false){
		var cue1 = document.getElementById("fuser_cue");
		cue1.innerHTML = "<img src='./images/cue/IconRun.gif' />验证中";
		action=1;
	}
	else if(user!=""&& regtext.test(user)==false){
		var cue2 = document.getElementById("user_cue");
		cue2.innerHTML = "<img src='./images/cue/IconRun.gif' />验证中";
		action=2;
	}else{
		return false;
	}
	if(action!=0){
		$.ajax({
			url:'../ajax/checkdata.php',
			type:'post',
			data:{act:"checkadmin",fuser:fuser,user:user,adminid:adminid},
			success:function(data){
				data=data.replace(/(^\s+)|(\s+$)/g,"");//去除空格
				//alert(data);return false;
		        var dataObj=eval("("+data+")");
		        if (data) {//true
	               	if (dataObj.root[0].status == "true") {
	               		if(action==1)cue1.innerHTML=dataObj.root[0].Description;
	               		if(action==2)cue2.innerHTML=dataObj.root[0].Description;
					   }else{
						if(action==1)cue1.innerHTML=dataObj.root[0].Description;
		               	if(action==2)cue2.innerHTML=dataObj.root[0].Description;
					   }

					}else {//false
						if(action==1)cue1.innerHTML=dataObj.root[0].Description;
	               		if(action==2)cue2.innerHTML=dataObj.root[0].Description;
					}

			},
			error:function(erg){
				ymPrompt.errorInfo({title:'系统提示',message:'出错啦...'});
			}
		});
	}
}